import { DirectiveBinding, nextTick } from 'vue'
const bottomDirective = {
  updated: (el: HTMLElement, bind: DirectiveBinding) => {
    const effect = bind.value
    cacheFn(effect, () => {
      nextTick(() => {
        el.scrollTop = el.scrollHeight
      })
    })
  }
}
const cache = () => {
  let cacheValue: any = null
  return (value: any, cb: Function) => {
    if (cacheValue === value) {
      return
    } else {
      cacheValue = value
      cb()
    }
  }
}
const cacheFn = cache()
export default bottomDirective
